import { defineStore } from 'pinia'
import { ref } from 'vue'

type Token = string | null
type UserInfo = any | null

const useUserStore = defineStore('user', {
  state: () => ({
    token: ref(null),
    userInfo: ref(null),
  }),
  getters: {
    isLogin: (state) => {
      return state.token !== null
    },
  },
  actions: {
    setToken(token: Token) {

    },
    setUserInfo(userInfo: UserInfo) {
      this.userInfo = userInfo
    },
    clearUserInfo() {
      this.token = null
      this.userInfo = null
    },
  }
})

export default useUserStore
